/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entities;

import Connection.Koneksi;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Tea-Nose
 */
public class Servis {

    private String kode_servis;
    private String catatan_servis;
    private String tanggal_servis;
    private boolean status_oli;
    private double biaya_servis;
    private String no_polisi;

    /**
     * @return the kode_servis
     */
    public String getKode_servis() {
        return kode_servis;
    }

    /**
     * @param kode_servis the kode_servis to set
     */
    public void setKode_servis(String kode_servis) {
        this.kode_servis = kode_servis;
    }

    /**
     * @return the catatan_servis
     */
    public String getCatatan_servis() {
        return catatan_servis;
    }

    /**
     * @param catatan_servis the catatan_servis to set
     */
    public void setCatatan_servis(String catatan_servis) {
        this.catatan_servis = catatan_servis;
    }

    /**
     * @return the tanggal_servis
     */
    public String getTanggal_servis() {
        return tanggal_servis;
    }

    /**
     * @param tanggal_servis the tanggal_servis to set
     */
    public void setTanggal_servis(String tanggal_servis) {
        this.tanggal_servis = tanggal_servis;
    }

    /**
     * @return the ganti_oli
     */
    public boolean getStatus_oli() {
        return status_oli;
    }

    /**
     * @param ganti_oli the ganti_oli to set
     */
    public void setStatus_oli(boolean ganti_oli) {
        this.status_oli = ganti_oli;
    }

    /**
     * @return the biaya_servis
     */
    public double getBiaya_servis() {
        return biaya_servis;
    }

    /**
     * @param biaya_servis the biaya_servis to set
     */
    public void setBiaya_servis(double biaya_servis) {
        this.biaya_servis = biaya_servis;
    }

    public void getDataServisKendaraanBasedOnNoPolisi(String noPolisi) throws SQLException {
        String query = "select * form Servis where no_polisi = '" + noPolisi + "'";
        Koneksi.execute(query);
    }

    public void catatDataServisKendaraan() {
        try {
            String query = "INSERT INTO SERVIS(kode_servis,tanggal_servis,status_oli,catatan_servis,no_polisi) VALUES('"
                    + getKode_servis() + "','" + getTanggal_servis() + "','" + getStatus_oli() + "','" + getCatatan_servis() + "','"
                    + getNo_polisi() + "')";
            Koneksi.updateData(query);
        } catch (SQLException ex) {
            Logger.getLogger(Servis.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void dataServisKembali(Double i, String kode) {
        try {
            String query = "UPDATE servis set biaya_servis=" + i + "where kode_servis ='" + kode + "'";
            Koneksi.updateData(query);
        } catch (SQLException ex) {
            Logger.getLogger(Servis.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public String cariMaxKodeServis() {
        String couter = null;
        try {
            String query = "Select max(kode_servis)+1 from servis";
            ResultSet rs = Koneksi.select(query);
            while (rs.next()) {
                if (rs.getString(1) == null) {
                    couter = "" + 1;
                } else {
                    couter = rs.getString(1);
                }
            }
        } catch (SQLException ex) {
            Logger.getLogger(Servis.class.getName()).log(Level.SEVERE, null, ex);
        }
        return couter;
    }

    /**
     * @return the no_polisi
     */
    public String getNo_polisi() {
        return no_polisi;
    }

    /**
     * @param no_polisi the no_polisi to set
     */
    public void setNo_polisi(String no_polisi) {
        this.no_polisi = no_polisi;
    }

    public String ambilTanggalServis(String noPolisi) throws SQLException {
        String query = "select tanggal_servis from servis where no_polisi='" + noPolisi + "' and tanggal_servis>sysdate";
        ResultSet rs = Koneksi.select(query);
        while (rs.next()) {
            return rs.getString(1);
        }
        return null;
    }
}
